package cn.swing.his.element.webapi.service;

import cn.swing.his.element.service.IArticleService;
import cn.swing.his.element.webapi.mapper.ArticleMapper;
import cn.swing.his.pojo.element.entity.Article;
import cn.swing.his.pojo.element.entity.Category;
import cn.swing.his.pojo.element.vo.ArticleDetailsVO;
import cn.swing.his.pojo.element.vo.ArticleHomeVO;
import cn.swing.his.pojo.element.vo.CategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


@Service
public class ArticleServiceImpl implements IArticleService{

    @Autowired
    private ArticleMapper articleMapper;
    //添加类别
    @Override
    public int insertCategory(Category category) {
        return articleMapper.insertCategory(category);
    }
    //根据id删除类别
    @Override
    public int deleteCategoryById(Long id) {
        return articleMapper.deleteCategoryById(id);
    }
    @Override
    public List<CategoryVO> selectCategory() {
        System.out.println(articleMapper.selectCategory());
        return articleMapper.selectCategory();
    }
    //根据文章id查询文章
    @Override
    public List<ArticleDetailsVO> selectArticleByCategoryId(Integer categoryId) {
        return articleMapper.selectArticleByCategoryId(categoryId);
    }
    //上传文章
    @Override
    public int uploadArticle(Article article){
        return articleMapper.uploadArticle(article);
    }
    //根据id删除文章
    @Override
    public int deleteArticleById(Long id) {
        int rows = articleMapper.deleteArticleById(id);
        return rows;
    }
    @Override
    public List<ArticleHomeVO> selectArticleHome() {
        System.out.println("ArticleServiceImpl.selectArticleHome");
        System.out.println(articleMapper.selectArticleHome());
        return articleMapper.selectArticleHome();
    }

}
